# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def insertIntoBST(self, root: TreeNode, val: int) -> TreeNode:
        if root is None:
            return TreeNode(val)
        def show(node,indent):
            if node.left is not None:
                print(" "*indent+"left "+str(node.left.val))
                show(node.left,indent+1)
            if node.right is not None:
                print(" "*indent+"right "+str(node.right.val))
                show(node.right,indent+1)

        def findnode(node,val):
            if node.val<val:
                if node.right is not None:
                    findnode(node.right,val)
                else:
                    node.right=TreeNode(val)
                    return
            if node.val>val:
                if node.left is not None:
                    findnode(node.left,val)
                else:
                    node.left=TreeNode(val)
                    return 
        findnode(root,val)
        return root
            